package summary;

import java.util.Stack;

/**
 * @Author: 海琳琦
 * @Date: 2022/3/10 14:32
 * https://leetcode-cn.com/problems/implement-queue-using-stacks/
 */
public class Title232 {

    static Stack<Integer> stackIn;
    static Stack<Integer> stackOut;

    public Title232() {
        stackIn = new Stack<>();
        stackOut = new Stack<>();
    }

    public void push(int x) {
        stackIn.push(x);
    }

    public int pop() {
        if (stackOut == null) {
            while (!stackIn.isEmpty()) {
                stackOut.push(stackIn.pop());
            }
        }
        return stackOut.pop();
    }

    public int peek() {
        if (stackOut == null) {
            while (!stackIn.isEmpty()) {
                stackOut.push(stackIn.pop());
            }
        }
        return stackOut.peek();
    }

    public boolean empty() {
        return stackIn.isEmpty() && stackOut.isEmpty();
    }

    public static void main(String[] args) {

    }
}
